<template>
  <div>
    <el-form ref="form" :model="form" label-width="100px">
      <ElFormItem label="用户名" prop="username">{{form.username}}</ElFormItem>
      <ElFormItem label="姓名" prop="name">
        <el-input v-model="form.name"></el-input>
      </ElFormItem>
      <ElFormItem label="所在部门" prop="department">
        <el-input v-model="form.department"></el-input>
      </ElFormItem>
      <ElFormItem label="新密码" prop="newpass">
        <el-input v-model="form.newpass" type="password" placeholder="请输入新密码"></el-input>
      </ElFormItem>
      <ElFormItem>
        <el-button type="primary" @click="onSubmit">确认</el-button>
      </ElFormItem>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: "",
        name: "",
        department: "",
        newpass: ""
      }
    };
  },
  created() {
    this.getpassinfo();
  },
  methods: {
    onSubmit() {
      this.axios
        .post("/updateadmininfo", JSON.stringify(this.form))
        .then(response => {
          if (response.data.success == 1) {
            this.$message({
              message: "提交成功",
              type: "success"
            });
          } else {
            this.$message({
              message: "提交失败",
              type: "warning"
            });
          }
        });
    },
    getpassinfo() {
      this.axios
        .get("/getpassinfo")
        .then(response => {
          this.form.username = response.data.username;
          this.form.name = response.data.name;
          this.form.department = response.data.department;
        })
        .catch(error => {
          console.log(error);
        });
    }
  }
};
</script>
